package hidalgo.expenses.widgets;

import hidalgo.expenses.R;
import hidalgo.expenses.entities.Transaction;
import hidalgo.expenses.utils.Util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class TransactionItemView extends RelativeLayout {

	private TextView txtDate;
	private TextView txtDescription;
	private TextView txtAmount;
	
	private Transaction transaction;

	public TransactionItemView(Context context, Transaction transaction) {
		super(context);
		inflateLayout(context);

	}

	public TransactionItemView(Context context) {
		super(context);
		inflateLayout(context);

	}

	public TransactionItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		inflateLayout(context);

	}

	private void inflateLayout(Context context) {
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.transaction_item, this);

		this.txtAmount = (TextView) view.findViewById(R.id.txtAmount);
		this.txtDate = (TextView) view.findViewById(R.id.txtDate);
		this.txtDescription = (TextView) view.findViewById(R.id.txtDescription);
	}

	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;

		if (transaction != null) {
			txtAmount.setText(Util.moneyFormat.format(transaction.getAmount()));
			txtDate.setText(Util.getStringFromDate(transaction.getDate(), Util.SIMPLE_DATE_FORMAT));
			txtDescription.setText(transaction.getDescription());
		}
	}

	public Transaction getTransaction() {
		return transaction;
	}

}
